package rs.etf.mips.crossroad.logic.lightcontrol;

import java.util.EnumMap;

import rs.etf.mips.crossroad.logic.Crossroad;

public class LightStateFactory {

	private static LightStateFactory instance;
	
	private EnumMap<LightStateDescriptor, LightState> states;
	
	static LightStateFactory instance() {
		return instance;
	}
	
	public static LightStateFactory instance(Crossroad crossroad, long defaultLightStateLength) {
		if (instance == null) {
			instance = new LightStateFactory(crossroad, defaultLightStateLength);
		}
		return instance;
	}

	private LightStateFactory(Crossroad crossroad, long defaultLightStateLength) {
		states = new EnumMap<>(LightStateDescriptor.class);
		states.put(LightStateDescriptor.HorizontalForward, new LightStateHorizontalForward(crossroad, defaultLightStateLength));
		states.put(LightStateDescriptor.HorizontalLeftRight, new LightStateHorizontalLeftRight(crossroad, defaultLightStateLength));
		states.put(LightStateDescriptor.HorizontalRightForward, new LightStateHorizontalRightForward(crossroad, defaultLightStateLength));
		states.put(LightStateDescriptor.VerticalForward, new LightStateVerticalForward(crossroad, defaultLightStateLength));
		states.put(LightStateDescriptor.VerticalLeftRight, new LightStateVerticalLeftRight(crossroad, defaultLightStateLength));
		states.put(LightStateDescriptor.VerticalRightForward, new LightStateVerticalRightForward(crossroad, defaultLightStateLength));
	}
	
	public LightState getLightState(LightStateDescriptor descriptor) {
		return states.get(descriptor);
	}
}
